<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class API extends CI_Controller{

	public function __construct(){
		parent::__construct();
		$this->load->model('member_model', 'member');
		$this->load->helper('public');
	}

	public function check_email_available() {
		$email = $this->input->post('email');
		$emailPattern = "/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$/u";
		if (preg_match($emailPattern, $email)) {
			$member = $this->member->select_one_by_field('email', $identification);

			if (!empty($member)) {
				echo "{\"type\":\"email\", \"message\":\"existed\"}";
			} else {
				echo "{\"type\":\"email\", \"message\":\"not existed\"}";
			}
		} else {
			echo "{\"type\":\"email\", \"message\":\"invalid\"}";
		}
	}

	public function captcha() {
		$this->load->library('Captcha');
		$this->captcha->CreateImage();
	}

}